import React from 'react';
import {postUrl} from "../../utils/request"
import {useNavigate} from "react-router-dom"
import { Form, Input, Button, Message, message } from 'antd';
import "./style.scss"

const Index = () => {
    const navigate=useNavigate()
    const onFinish = async(values) => {
        const res=await postUrl('/login',values)
        const {code,mes}=res.data
        if(code===200){
            message.success(mes)
            navigate('/home')
        }else{
            message.error(mes)
        }
    };
    return (
        <div>
            <div className="loginWrap">
            <Form
                name="basic"
                labelCol={{
                    span: 8,
                }}
                wrapperCol={{
                    span: 16,
                }}
                initialValues={{
                    remember: true,
                }}
                onFinish={onFinish}
                autoComplete="off"
            >
                <Form.Item
                    label="用户名"
                    name="username"
                    rules={[
                        {
                            required: true,
                            message: '请输入您的用户名!',
                        },
                    ]}
                >
                    <Input />
                </Form.Item>

                <Form.Item
                    label="密码"
                    name="password"
                    rules={[
                        {
                            required: true,
                            message: '请输入您的密码!',
                        },
                    ]}
                >
                    <Input.Password />
                </Form.Item>

                <Form.Item
                    wrapperCol={{
                        offset: 8,
                        span: 16,
                    }}
                >
                    <Button type="primary" htmlType="submit">
                        登录
                    </Button>
                </Form.Item>
            </Form>
            </div>
        </div>
    );
}

export default Index;
